﻿@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiList.cshtml"; }

<fieldset class="table-fieldset" id="searchfield" style="display:none">
    <legend>搜索信息</legend>
    <div style="margin: 5px 5px 5px 5px">
        <form class="layui-form" action="">
            <div class="layui-inline">
                <input class="layui-input" placeholder="关键字" name="key" id="key" autocomplete="off">
            </div>
            <div class="layui-inline">
                <button type="button" class="layui-btn layui-btn-primary" id="search"><i class="layui-icon layui-icon-search"></i></button>
                <button type='reset' class='layui-btn layui-btn-primary'><i class='layui-icon layui-icon-refresh'></i></button>
            </div>
        </form>
    </div>
</fieldset>
<!--数据表格-->
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>

<script>
    layui.use(["table", "form", "exLayer", "exUtils", "miniPage"], function () {
        let table = layui.table;
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let miniPage = layui.miniPage;

        let $ = layui.$;

        form.render(); //初始化表单，要加上，不然刷新部分组件可能会不加载

        let ThisTable = table.render({
            elem: "#tableId",
            url: "/SysBasic/Notify/GetList?key=" + $("#key").val(),
            limits: [10, 50, 100],
            limit: 10,
            page: true,
            defaultToolbar: [{ title: '刷新显示所有数据', layEvent: 'refresh', icon: 'layui-icon-refresh' }, 'filter', 'exports'],
            toolbar: "#toolbarTpl",
            cols: [[
                { field: "Subject", title: "标题", width: 120, sort: true },
                { field: "Content", title: "内容", sort: true },
                { field: "FromId", title: "发布人", width: 80, sort: true },
                { field: "publishTime", title: "发布时间", width: 120, sort: true },
                { title: "操作", width: 80, align: "center", fixed: "right", templet: "#operationTpl" }
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "add":
                    add();
                    break;
                case "refresh":
                    refresh();
                    break;
            }
        });

        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "edit":
                    edit(data.NotifyId);
                    break;
                case "del":
                    del(data.NotifyId);
                    break;
            }
        });

        function add() {
            exLayer.open("添加通知", "/SysBasic/Notify/Add", '100%', '100%', '0px', '0px', null, null);
        }

        function edit(id) {
            exLayer.open("编辑分类", "/SysBasic/Notify/Edit?id="  + id, '100%', '100%', '0px', '0px', null, null);
        }

        function del(id) {
            exLayer.confirm("确定要删除吗？", function () {
                exUtils.ajax("/SysBasic/Notify/Delete", "get", { id: id }, true).done(function (response) {
                    exUtils.tableSuccessMsg(response.message);
                    $(".layui-laypage-btn")[0].click();
                }).fail(function (error) {
                    console.log(error);
                });
            })
        }

        function refresh() {
            ThisTable.reload({
                url: "/SysBasic/Notify/GetList?key=" + $("#key").val()
            });
        }
    });
</script>
<script type="text/html" id="toolbarTpl">
    <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="add" id="add"><i class="fa fa-plus"></i>添加通知</button>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    @*<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" id="edit">编辑</a>*@
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" id="del">删除</a>
</script>